package com.xiaof.store.service.impl;

import com.xiaof.store.entity.District;
import com.xiaof.store.mapper.DistrictMapper;
import com.xiaof.store.service.IDistrictService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 *
 * @ProjectName: store
 * @Package: com.xiaof.store.service.impl
 * @ClassName: DistrictServiceImpl
 * @Author: xiaof
 * @Description:
 * @Date: 2022/1/7 21:03
 * @Version: 1.0
 */
@Service
public class DistrictServiceImpl implements IDistrictService {
    @Autowired
    private DistrictMapper districtMapper;
    @Override
    public List<District> getByParent(String parent) {
        List<District> list = districtMapper.findByParent(parent);
        //将无关数据设置为null
        for (District district : list) {
            district.setId(null);
            district.setParent(null);
        }
        return list;
    }

    @Override
    public String getNameByCode(String code) {
        return districtMapper.findNameByCode(code);
    }
}
